package com.cr.backbone.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

public class ApplicationDateTypeConverter extends StrutsTypeConverter{

	SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
	
	/**
	 * String to Object
	 * Jsp ==> Action
	 * 
	 */
	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
		if(arg1[0] instanceof String){
			try {
				return sdf.parse(arg1[0]);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * Object to String
	 * Action ==> Jsp 
	 */
	@Override
	public String convertToString(Map arg0, Object arg1) {
		if(arg1 instanceof Date)
			return sdf.format(arg1);
		return null;
	}

}
